package cn.powertime.evaluation.app.controller;


import cn.powertime.evaluation.facade.DbqPostingsFacade;
import cn.powertime.evaluation.vo.*;
import cn.powertime.evaluation.web.controller.BaseController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 帖子表 前端控制器
 * </p>
 *
 * @author liqi
 * @since 2019-09-23
 */
@RestController
@RequestMapping("/app/dbq-postings")
@Api(value = "/app/dbq-postings", tags = "帖子接口", produces = MediaType.ALL_VALUE)

public class AppDbqPostingsController extends BaseController {

    @Autowired
    private DbqPostingsFacade dbqPostingsFacade;

    @ApiOperation(value = "发布帖子", notes = "")
    @PostMapping("/add")
    public Object add(@Validated @RequestBody ReqPostingsAddVo addVo) {
        boolean b = dbqPostingsFacade.add(addVo);
        if(b){
            return success("发帖成功");
        }
        return error("发帖失败");
    }

    @ApiOperation(value = "标签列表", notes = "")
    @GetMapping("/lableList")
    public Object lableList() {
        List<RespLableListVo> list = dbqPostingsFacade.lableList();
        return success(list);
    }

    @ApiOperation(value = "帖子列表",response = WebRespPostingsListVo.class)
    @PostMapping(value = "/postingsList")
    public Object list(@RequestBody ParamPageVo<WebReqPostingsSearchVo> vo) {
        IPage<WebRespPostingsListVo> list = dbqPostingsFacade.postingsList(vo);
        return success(list);
    }

    @ApiOperation(value = "帖子关注/取消关注,收藏/取消收藏,点赞/取消点赞,浏览")
    @PostMapping(value = "/event")
    public Object event(@Validated @RequestBody WebReqPostingsEventVo vo) {
        boolean b = dbqPostingsFacade.event(vo);
        if(b){
            return success("成功");
        }
        return error("失败");
    }

    @ApiOperation(value = "帖子评论")
    @PostMapping(value = "/comment")
    public Object comment(@Validated @RequestBody WebReqPostingsCommentVo vo) {
        boolean b = dbqPostingsFacade.comment(vo);
        if(b){
            return success("评论成功");
        }
        return error("评论失败");
    }

    @ApiOperation(value = "帖子评论列表",response = WebRespPostingsCommentListVo.class)
    @PostMapping(value = "/commentList")
    public Object commentList(@RequestBody ParamPageVo<WebReqPostingsCommentSearchVo> vo) {
        IPage<WebRespPostingsCommentListVo> list = dbqPostingsFacade.commentList(vo);
        return success(list);
    }

    @ApiOperation(value = "帖子是否收藏，关注，点赞",response = WebRespPostingsEventVo.class)
    @PostMapping(value = "/postingsEvent")
    public Object comment(@Validated @RequestBody WebReqPostingsSearchEventVo vo) {
        WebRespPostingsEventVo b = dbqPostingsFacade.postingsEvent(vo);
        return success(b);
    }


}
